package com.theoryinpractice.hudson;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;

import java.util.HashSet;
import java.util.Set;

@State(
        name = "HudsonConfigurationManager",
        storages = {
        @Storage(
                id = "other",
                file = "$APP_CONFIG$/hudson.xml"
        )}
)
public class HudsonConfigurationManager implements PersistentStateComponent<HudsonConfigurationManager.ConfigurationBean> {
    private static final Logger LOGGER = Logger.getInstance("Hudson");

    private ConfigurationBean configuration;


    public HudsonConfigurationManager() {
        configuration = new ConfigurationBean();
    }

    public static HudsonConfigurationManager getInstance() {
        return ServiceManager.getService(HudsonConfigurationManager.class);
    }

    public static class ConfigurationBean {
        public Set<String> hudsonServers = new HashSet<String>();
    }


    public ConfigurationBean getState() {
        return configuration;
    }

    public void loadState(final ConfigurationBean object) {
        LOGGER.info("Loading Hudson Configuration State");
        configuration = object;

    }
}
